$(function(){
	for(var i=1;i<200;i++){
		$("#minAge").append("<option value="+i+">"+i+"</option>");
	}
	$("#minAge").change(function(){
		$("#maxAge").html("<option value='0'>请选择年龄...</option>");
		for(var i=1;i<200;i++){
			if($('#minAge').val()<i){
				$("#maxAge").append("<option value="+i+">"+i+"</option>");
			}
		}
	})

    /**------------重置---------------*/
    $(".btn-reset").click(function() {
    	$("#form_searh")[0].reset();
    	return false; 
    });
	
	/**------------推送------------------*/
	$(".btn-primary").click(function() {
		var gender = $("input[name='gender']:checked").val();
		var minAge = $("#minAge").val();
		var maxAge = $("#maxAge").val();
		var title = $("#title").val();
		var url = $("#url").val();
		var content = $("#content").val();
		var alias = $("input[name='alias']:checked").val();
		var type = $("input[name='type']:checked").val();
		var sendTime = $("input[name='sendTime']:checked").val();
		if(title ==""){
			warnInput($("#title"));
			return false;
		}
		if(content ==""){
			warnInput($("#content"));
			return false;
		}
		var time = "";
		if(sendTime == 1){
			time = sendTime; 	
		}else{
			if(!$("#datetimepicker").val().match(/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/)){
				warnInput($("#unloadValue"));
				return false;
			}else{
				time = $("#datetimepicker").val();
			}
		}
		$.post(serverURL + "push/add", {"title" : title,"url" : url,"content" : content,"gender":gender,"minAge" : minAge,"maxAge" : maxAge,"alias" : alias,"type":type,"sendTime":time}, function(data) {
				if (data.code == 0) {
					alert("推送成功 !");
				}else if(data.code!=-1){
					alert("推送失败");
				}
		});
		
	});
	
	$("#datetimepicker").datetimepicker({
		format: "yyyy-mm-dd hh:ii:ss",
		language:"zh-CN",
		startView:4,
		minView:0,
		autoclose: true,
	    todayBtn: true,
	    pickDate: true,
	    pickTime: true,
	    todayHighlight:true,
	    keyboardNavigation:true
	});
	
	 $("input[name='sendTime']").click(function(){
		if($(this).val() ==0){
			$("#datetimepicker").show();
		}else{
			$("#datetimepicker").hide();
		}
	 });
});	
	